package com.resou.reader.data.readhistory;

import com.resou.reader.api.entry.Result;
import com.resou.reader.data.Injection;
import com.resou.reader.data.bookshelf.model.ReadRecord;

import io.reactivex.Observable;
import retrofit2.Call;

public class ReadHistoryRepository {
    private static ReadHistoryRepository sInstance;
    private final ReadRecordService mReadRecordService;

    public static ReadHistoryRepository getInstance() {
        if (sInstance == null) {
            sInstance = new ReadHistoryRepository();
        }
        return sInstance;
    }

    public ReadHistoryRepository() {
        mReadRecordService = Injection.provideReadRecordService();
    }

    public Observable<Result> clearReadRecord(String token) {
        return mReadRecordService.clearReadRecord(token);
    }

    public Observable<Result> syncReadingRecord(String token, String bookId, String chapterId) {
        return mReadRecordService.saveReadingRecord(token, bookId, chapterId);
    }

    public Call<Result> uploadReadingRecord(String token, String bookId, String chapterId) {
        return mReadRecordService.uploadReadingRecord(token, bookId, chapterId);
    }

    public Observable<Result<ReadRecord>> loadRemoteRecord(String token, int page, int pageSize) {
        return mReadRecordService.getReadRecord(token, page, pageSize);
    }
}
